<!DOCTYPE html>
<html>
<head th:include="cultivateWeb/header :: culHeaderCss">

</head>
<link type="text/css" href="/css/cultivateWeb/style/news.css" rel="stylesheet">
<link rel="stylesheet" href="/css/cultivateWeb/style/apply.css">
<body>
<!-- 顶部导航 -->
<header th:include="cultivateWeb/header :: header"></header>
<div style="clear: both"></div>
<div style="background-color: #f7f7f7; ">
    <div style="height: 40px">
        <p style="margin: 0px auto auto 380px; line-height: 40px">当前位置：<a href="/cultivate/homepage">首页</a> > 机构编辑</p>
    </div>

    <!--<div style="width: 1200px; margin: auto">
        <span class="title gg" a="0" >培训机构申请</span>
        <span class="title1 gg" a="1">实训机构申请</span>
    </div>-->
    <hr style="margin: auto auto 40px auto  ; width: 1200px"/>

    <!-- 行业信息 -->
    <section id="info" style="">
        <div style="width: 1150px;margin:0 auto;">
            <form id="formId">
                <input type="hidden" id="orgId" th:value="${orgId}"/>
            </form>
        </div>
        <div style="clear: both"></div>
    </section>
</div>
<!-- footer ------------------------------------------------------- -->
<div class="footer" th:include="cultivateWeb/header :: footer"></div>
<script src="/js/plugins/layer/layer.min.js" th:src="@{/js/plugins/layer/layer.min.js}"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/js/plugins/validate/jquery.validate.extend.js"></script>
<script src="/js/layui/layui.js"></script>
<!--<script src="/js/certificateWeb/main.js"></script>-->
<script src="/js/content.js"></script>
<script src="/js/jquery.citys.js"></script>
<script>


    $(function () {
        ajaxToken("/cultivate/orgSelInfo", "GET", {
            orgId: $("#orgId").val()
        }, function (res) {
            var info =
                '<input type="hidden" name="orgRoleId" id="roleId" value="' + res.roleId + '"/>' +
                '<div class="div_3">' +
                '<label class="span_1">机构logo：</label>' +
                '<button type="button" class="btn inp_1" style="margin-top: 20px" id="btnUpload1">' +
                '<i class="fa fa-cloud"></i>上传图片' +
                '</button>' +
                '<input type="text" style="opacity:0;width: 1px;" id="orgPhoto" name="orgPhoto" value="' + res.orgPhoto + '"/>' +
                '</div>' +
                '<div class="div_3"><img id="zp" style="width:200px" src="' + res.orgPhoto + '"></div>' +
                '<div class="div_3">' +
                '<label class="span_1">站点类型<span style="color: #D52525">*</span>：</label>' +
                '<input type="hidden" id="roleType1" value="' + res.roleType + '"/>' +
                '<select name="roleType" id="roleType" class="form-control inp_1">' +
                '<option value="">请选择</option>' +
                '<option value="0">培训机构</option>' +
                '<option value="3">实习就业单位</option>' +
                '</select>' +
                '</div>' +
                '<div class="div_3">' +
                '<label class="span_1">机构类型<span style="color: #D52525">*</span>：</label>' +
                '<input type="hidden" value="' + res.type + '" id="orgType1"/>' +
                '<select name="orgType" id="orgType" class="form-control inp_1">' +
                '<option value="">请选择</option>' +
                '<option value="1">机关</option>' +
                '<option value="0">企业</option>' +
                '<option value="2">事业单位/学校</option>' +
                '<option value="3">社会团体</option>' +
                '<option value="4">其它组织机构</option>' +
                '</select>' +
                '</div>' +
                '<div class="div_3 px" style="display: none">' +
                '<label class="span_1">申请负责证书<span style="color: #D52525">*</span>：</label>' +
                '<input name="profileId" value="' + res.profileId + '" id="profileId" placeholder="请选择申请负责证书" class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3">' +
                '<label class="span_1">机构名称<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" name="name" value="' + res.name + '" id="name" placeholder="请输入机构名称" class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3">' +
                '<label class="span_1">机构代码<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" name="orgCode" value="' + res.orgCode + '" id="orgCode" placeholder="请输入社会信用代码/院校代码" class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3">' +
                '<label class="span_1">法人代表<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" id="legalRepresentative" value="' + res.legalRepresentative + '" placeholder="请输入法人代表" name="legalRepresentative" class="form-control inp_1"/>' +
                '</div>' +
                ' <!--企业申请独有字段-->' +
                '<div class="div_3 company" style="display: none">' +
                '<label class="span_1">营业范围<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" id="scopeOfBusiness" value="' + res.scopeOfBusiness + '" placeholder="请输入营业范围" name="scopeOfBusiness"  class="form-control inp_1"/>' +
                '<div style="clear: none"></div>' +
                '</div>' +
                '<div class="div_3 company" style="display: none">' +
                '<label class="span_1">员工数量<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" id="staffSize" value="' + res.staffSize + '" name="staffSize"' +
                'placeholder="请输入员工数量"' +
                'class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3 company" style="display: none">' +
                '<label class="span_1">员工学历层次<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" id="staffArrangement" value="' + res.staffArrangement + '"' +
                'placeholder="请输入员工学历层次" name="staffArrangement"' +
                'class="form-control inp_1"/>' +
                '</div>' +
                '<!--学校申请独有字段-->' +
                '<div class="div_3 school" style="display: none">' +
                '<label class="span_1">学校性质<span style="color: #D52525">*</span>：</label>' +
                '<input type="hidden" name="schoolNature" value="' + res.schoolNature + '" id="schoolNature1"/>' +
                '<select  id="schoolNature" class="form-control inp_1">' +
                '<option value="">请选择</option>' +
                '<option value="0">中职</option>' +
                '<option value="1">高职</option>' +
                '<option value="2">本科</option>' +
                '</select>' +
                '</div>' +
                '<div class="div_3 school" style="display: none">' +
                '<label class="span_1">考生数<span style="color: #D52525">*</span>：</label>' +
                '<input type="number" id="numberOfExaminees" value="' + res.numberOfExaminees + '"' +
                'placeholder="请输入考生数" name="numberOfExaminees"' +
                'class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3 school" style="display: none">' +
                '<label class="span_1">师资力量(200字以内)<span style="color: #D52525">*</span>：</label>' +
                '<input type="text" id="teacherResources" maxlength="200" value="' + res.teacherResources + '"' +
                'placeholder="请输入师资力量" name="teacherResources"' +
                'class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3 px" style="display: none">' +
                '<label class="span_1">培训工种：</label>' +
                '<input type="text" id="trainingJobs" value="' + res.trainingJobs + '" name="trainingJobs"' +
                'placeholder="请输入培训工种" class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3 px" style="display: none">' +
                '<label class="span_1">培训层次：</label>' +
                '<input type="text" id="trainingArrangement" value="' + res.trainingArrangement + '"' +
                'name="trainingArrangement" placeholder="请输入培训层次" class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3 px" style="display: none">' +
                ' <label class="span_1">培训人数：</label>' +
                '<input type="number" id="trainingPerson" value="' + res.trainingPerson + '" name="trainingPerson"' +
                'placeholder="请输入培训人数" class="form-control inp_1"/>' +
                '</div>' +
                '<div class="div_3">' +
                '<label class="span_1">单位/学校地址<span style="color: #D52525">*</span></label>' +
                '<textarea type="text" id="address" style="height: 60px" name="address"' +
                '                           placeholder="请输入单位/学校地址" class="form-control inp_1">' + res.address + '</textarea>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">所属行业：</label>' +
                '                    <input type="text" id="industry" value="' + res.industry + '" name="industry"' +
                '                           placeholder="请输入所属行业" class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">机构规模：</label>' +
                '                    <input type="text" id="orgSize" value="' + res.orgSize + '" name="orgSize" placeholder="请输入机构规模"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">机构特色：</label>' +
                '                    <input type="text" id="orgItem" value="' + res.orgItem + '" name="orgItem" placeholder="请输入机构特色"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">联系人姓名<span style="color: #D52525">*</span>：</label>' +
                '                    <input type="text" id="contacts" value="' + res.contacts + '" name="contacts"' +
                '                           placeholder="请输入联系人姓名" class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">联系人职务<span style="color: #D52525">*</span>：</label>' +
                '                    <input type="text" id="contactsPost" value="' + res.contactsPost + '" name="contactsPost"' +
                '                           placeholder="请输入联系人职务"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">联系人手机号<span style="color: #D52525">*</span>：</label>' +
                '                    <input type="text" id="mobile" value="' + res.mobile + '" name="mobile" placeholder="请输入联系人手机号"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">办公座机号：</label>' +
                '                    <input type="text" id="workPhoneNum" value="' + res.workPhoneNum + '" name="workPhoneNum" placeholder="请输入电子邮箱"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">电子邮箱：</label>' +
                '                    <input type="text" id="email" value="' + res.mailbox + '" name="email" placeholder="请输入电子邮箱"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">网址：</label>' +
                '                    <input type="text" id="url" value="' + res.url + '" name="url" placeholder="请输入网址"' +
                '                           class="form-control inp_1"/>' +
                '                </div>' +
                '                <div class="div_3" id="adre1">' +
                '                    <label class="span_1">机构所在省份<span style="color: #D52525">*</span>：</label>' +
                '                    <input type="hidden" value="' + res.province + '" id="province" placeholder="企业所在份" ' +
                '                           class="form-control inp_1"/>' +
                '                    <select class="form-control inp_1" id="province" name="province">' +
                '                   </select>' +
                '                </div>' +
                '                <div class="div_3">' +
                '                    <label class="span_1">附件<span style="color: #D52525">*</span>：</label>' +
                '                    <button type="button" class="btn inp_1" style="margin-top: 20px" id="btnUpload">' +
                '                        <i class="fa fa-cloud"></i>上传文件' +
                '                    </button>' +
                '                    <input type="text" style="opacity:0;width: 1px;" value="'+res.enclosure+'" id="enclosure" name="enclosure"/>' +
                '                    <span id="test">' + res.enclosure + '</span>' +
                '                </div>' +
                '                <div class="div_3" style="width: 1000px">' +
                '                    <label class="span_1">机构介绍(200字以内)：</label>' +
                '                    <textarea type="text" maxlength="200" style="width:800px;height:150px;float: left;margin: 20px auto auto auto;" id="introduce" name="introduce" placeholder="请输入机构介绍"' +
                '                              class="form-control inp_1">' + res.introduce + '</textarea>' +
                '                </div>' +
                // '                <div class="div_3" th:each="xz:${consultations}" style="display: none">' +
                // '                    <label class="span_1">附件模板下载：</label>' +
                // '                    <label style="height: 50px;float: left;margin: 20px 10px auto auto;font-size: 16px;line-height: 50px;">' +
                // '                        <a target="_blank" style="color: blue" download th:href="${xz.files}" th:text="${xz.title}"></a>' +
                // '                    </label>' +
                // '                </div>' +
                '                <div class="div_3">' +
                '                    <button class="form-control but_1" id="send" type="submit">提交</button>' +
                '                </div>' +
                '<div style="clear: both"></div>';

            $("#formId").html(info);

            $('#adre1').citys({
                province: $("#province").val(),
                onChange: function (info) {
                }
            }, function (api) {

            });
            validateRule();
            selprofile()

            $("#orgType").change(function () {
                if ($(this).val() == 0) {
                    $(".company").css("display", "block");
                } else {
                    $(".company").css("display", "none");
                }

                if ($(this).val() == 2) {
                    $(".school").css("display", "block");
                } else {
                    $(".school").css("display", "none");
                }
            });

            $("#roleType").change(function () {
                if ($("#roleType").val() == 0 && $("#roleType").val() != "") {
                    $(".px").css("display", "block");
                } else {
                    $(".px").css("display", "none");
                    $("#profileId").val("");
                    $("#trainingJobs").val("");
                    $("#trainingPerson").val(0);
                    $("#trainingArrangement").val("")
                }
            })

            layui.use('upload', function () {
                var upload = layui.upload;
                //执行实例
                upload.render({
                    elem: '#btnUpload', //绑定元素
                    url: '/jzApi/utils/fileImprot', //上传接口
                    size: 1000,
                    accept: 'file',
                    done: function (r) {
                        $("#enclosure").val(r.data);
                        $("#test").html(subFileName(r.data));
                    },
                    error: function (r) {
                        layer.msg(r.msg);
                    }
                });
                upload.render({
                    elem: '#btnUpload1', //绑定元素
                    url: '/jzApi/utils/fileImprot', //上传接口
                    size: 1000,
                    accept: 'images',
                    done: function (r) {
                        $("#orgPhoto").val(r.data);
                        $("#zp").attr("src",r.data);
                    },
                    error: function (r) {
                        layer.msg(r.msg);
                    }
                });
            });
            $("#roleType").val($("#roleType1").val())
            $("#orgType").val($("#orgType1").val());
            $("#schoolNature").val($("#schoolNature1").val())
            if ($("#scopeOfBusiness").val() == "null") {
                $("#scopeOfBusiness").val("")
            }
            if ($("#staffSize").val() == "null") {
                $("#staffSize").val("")
            }
            if ($("#staffArrangement").val() == "null") {
                $("#staffArrangement").val("")
            }

            if ($("#roleType").val() == 0) {
                $(".px").css("display", "block");
            } else {
                $(".px").css("display", "none");
            }
            if ($("#orgType").val() == 2) {
                $(".school").css("display", "block");
            } else {
                $(".school").css("display", "none")
            }

            if ($("#orgType").val() == 0) {
                $(".company").css("display", "block");
            } else {
                $(".company").css("display", "none");
            }
        })
        $("#schoolNature").change(function () {
            $("#schoolNature1").val($(this).val())
        })

        $('.gg').click(function () {
            if ($(this).attr("a") == 0) {
                $("#info").css("display", "inline");
                $("#notice").css("display", "none");
            }
            if ($(this).attr("a") == 1) {
                $("#notice").css("display", "inline");
                $("#info").css("display", "none");
            }
            $(this).addClass("title");
            $(this).siblings().removeClass("title");
            $(this).siblings().addClass("title1");


        })
    })


    function save() {
        console.log("212",$('#formId').serialize())
        ajaxTokenForm("/cultivate/saveOrg", "POST", $('#formId').serialize(), function () {
            location.href = "/cultivate/applyRecord"
        })
    }

    $.validator.setDefaults({
        submitHandler: function () {
            save();
        }
    });


    //证书下拉框
    function selprofile() {
        $.ajax({
            url: "/jzApi/certificates/selProfileFill",
            success: function (res) {
                $('#profileId').selectPage({
                    showField: 'name',
                    keyField: 'id',
                    data: res.data,
                    multiple: true,
                    searchField: 'name'
                });
            }
        });
    }

    function validateRule() {
        var icon = "<i style='color: red;font-size: 14px'>";
        var a = '</i>';
        $("#formId").validate({
            rules: {
                roleType: {
                    required: true
                },
                orgType: {
                    required: true
                },
                profileId: {
                    required: true
                },
                name: {
                    required: true
                },
                orgCode: {
                    required: true
                },
                address: {
                    required: true
                },
                legalRepresentative: {
                    required: true
                },
                introduce: {
                     maxlength:200
                },
                //企业
                scopeOfBusiness: {
                    required: true
                },
                staffSize: {
                    required: true
                },
                staffArrangement: {
                    required: true
                },
                //学校
                schoolNature: {
                    required: true
                },
                numberOfExaminees: {
                    required: true
                },
                teacherResources: {
                    required: true,
                    maxlength:200
                },
                contacts: {
                    required: true
                },
                contactsPost: {
                    required: true
                },
                mobile: {
                    required: true,
                    phoneAndMobile: true
                },
                province: {
                    required: true
                },
                enclosure: {
                    required: true
                }
            },
            messages: {
                roleType: {
                    required: icon + "请选择站点类型" +a
                },
                orgType: {
                    required: icon + "请选择机构类型"+a
                },
                profileId: {
                    required: icon + "请选择证书"+a
                },
                name: {
                    required: icon + "请输入机构名称"+a
                },
                orgCode: {
                    required: icon + "请输入机构代码"+a
                },
                address: {
                    required: icon + "请输入地址"+a
                },
                legalRepresentative: {
                    required: icon + "请输入法人代表"+a
                },

                //企业
                scopeOfBusiness: {
                    required: icon + "请输入营业范围"+a
                },
                staffSize: {
                    required: icon + "请输入员工数量"+a
                },
                staffArrangement: {
                    required: icon + "请输入员工学历层次"+a
                },
                //学校
                schoolNature: {
                    required: icon + "请选择学校性质"+a
                },
                numberOfExaminees: {
                    required: icon + "请输入考生数"+a
                },
                teacherResources: {
                    required: icon + "请输入师资力量"+a
                },

                contacts: {
                    required: icon + "请输入联系人姓名"+a
                },
                contactsPost: {
                    required: icon + "请输入联系人职务"+a
                },
                mobile: {
                    required: icon + "请输入联系人手机号"+a
                },
                province: {
                    required: icon + "请选择企业所在省份"+a
                },
                enclosure: {
                    required: icon + "请上传附件"+a
                }

            }
        })
    }


</script>
</body>
</html>